package com.jingyong.infosite.web;

import com.jingyong.infosite.dto.request.People;
import com.jingyong.infosite.dto.response.TestObjectResponse;
import io.swagger.annotations.Api;
import lombok.Cleanup;
import lombok.NonNull;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

/**
 * @author Hill Dong
 * @date 2018/1/25
 */
@RestController
@Api("Lombok测试接口2")
@Log
public class LombokTestCollection {

    @RequestMapping(value = "/test_lombok", method = RequestMethod.GET,
            produces = "application/json; charset=utf-8")
    public TestObjectResponse testLombok() {
        log.info("进入方法");

        TestObjectResponse response = new TestObjectResponse();
        response.setAge(23);
        response.setName("donghf");
        response.setBirthDay("2016-12-11");

        operateFile();
        log.info("执行完方法,对象内容" + response.toString());
        return response;
    }

    private String getName(@NonNull People people) {
        return people.getName();
    }

    private People generatePeople() {
    //    return People.builder().name("donghf").birthDay("2014-10-10").id(23).build();
        return null;
    }


    private void operateFile() {
        try {
            File file = new File("d:\\temp\\lombotTest.txt");
            @Cleanup InputStream is = new FileInputStream(file);
            byte[] buffer = new byte[1024];
            while(true) {
                int i = is.read(buffer);
                if(i == -1) {break;}
                System.out.println(buffer);
                String s = new String(buffer, "utf8");
                System.out.println(s);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
